{extend name="layout/layout" /}

{block name="style"}
	<style>
		.goods-list{
			background: #fff;
		}

		.goods-list .item{
			border-bottom: 1px solid #eee;
			display: flex;
		}

		.goods-list .item .goods-img{
			width: 120px;
			height: 120px;
			text-align: center;
		}

		.goods-list .goods-info{
			padding: 10px;
			flex: 1;
		}

		.success-number{
			float: right;
		}

		.group-goods a{
			background:linear-gradient(143deg,rgba(129,95,250,1) 0%,rgba(78,106,240,1) 100%);
			color: #fff;
			padding: 5px 15px;
			font-size: 10px;
			border-radius: 3px;
			z-index: 999;
			position: relative;
		}

	</style>
{/block}

{block name="main"}
	<div class="group-goods" id="groupGoods"  v-cloak>
		<div class="box">
			<div class="goods-list" v-if="goodsList">
				<div class="item" v-for="goods in goodsList">
					<div class="goods-img">
						<img :src="goods.original_image" class="img-responsive" alt="">
					</div>
					<div class="goods-info">
						<div class="goods-name ellipsis-2">{{goods.goods_name}}</div>
						<div class="number text-gray">{{goods.number}} 人拼 (已拼{{goods.success_number}})</div>
						<div class="price text-theme">
							<b>￥{{goods.group_price}}</b> &nbsp;&nbsp;&nbsp;
							<del class="text-gray">{{goods.shop_price}}</del>
						</div>
						<div class="btn-box mui-text-right">
							<a  @tap="toDetail(goods.goods_id)" >去拼团</a>
						</div>
					</div>
				</div>
			</div>

			<div class="no-data" v-else>没有相关商品</div>
		</div>
	</div>
{/block}

{block name="navbar"}{/block}

{block name="script"}
	<script>
		mui.init({
		  pullRefresh : {
		    container:"#groupGoods",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
		    down : {
		      style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
		      color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
		      height:'50px',//可选,默认50px.下拉刷新控件的高度,
		      range:'100px', //可选 默认100px,控件可下拉拖拽的范围
		      offset:'0px', //可选 默认0px,下拉刷新控件的起始位置
		      auto: false,//可选,默认false.首次加载自动上拉刷新一次
		      callback :function(){
		      	console.log('down');
		      	indexVue.goodsList = [];
		      	indexVue.page = 1;
		      	indexVue.nextPage = false;
		      	// mui('#pullup-container').pullRefresh().refresh(true);

		      	indexVue.getGoods();
		      	// mui('.group-goods').pullRefresh().endPulldown();
		      } //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
		    },
		    up : {
		      height:50,//可选.默认50.触发上拉加载拖动距离
		      auto:true,//可选,默认false.自动上拉加载一次
		      contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
		      contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
		      callback :function(){
		      	indexVue.getGoods();
		      	this.endPullupToRefresh(indexVue.nextPage);
		      } //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
		    }
		  }
		});
		var indexVue = new Vue({
			el:'.group-goods',
			data: {
				page: 1,
				nextPage: false,
				goodsList: []
			},
			mounted: function(){
				// this.getGoods();

			},
			methods: {
				//获取商品列表
				getGoods: function(){
					var that = this;
					var url =  'goods/groupGoods';
					request(that, {'url': url, 'data': {'page': that.page}}, function(res){
						if(res.code == 200) {
							that.goodsList = that.goodsList.concat(res.data);
							if(res.data.length < 20) {
								that.nextPage = true;
							}
							that.page++;
						} else {
							mui.toast(res.msg);
						}	
					});
				},

				toDetail: function(id) {
					location.href = '/mobile/goods/detail/id/'+id;
				}
			}
		});
	</script>
{/block}